# Maintainer: Alexey Pavlov <Alexpux@gmail.com>
# Contributor: Ray Donnelly <mingw.android@gmail.com>

_realname=mako
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
provides=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
conflicts=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
replaces=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
pkgver=1.1.2
pkgrel=1
pkgdesc="A super-fast templating language that borrows the best ideas from the existing templating languages (mingw-w64)"
arch=('any')
license=('custom')
url="https://pypi.python.org/pypi/Mako"
depends=("${MINGW_PACKAGE_PREFIX}-python-markupsafe"
         "${MINGW_PACKAGE_PREFIX}-python-beaker")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-setuptools")
checkdepends=("${MINGW_PACKAGE_PREFIX}-python-nose")
options=('staticlibs')
install=${_realname}3-${CARCH}.install
source=("https://pypi.org/packages/source/M/Mako/Mako-${pkgver}.tar.gz")
sha256sums=('3139c5d64aa5d175dbafb95027057128b5fbd05a40c53999f3905ceb53366d9d')

prepare() {  
  cd "${srcdir}"
  rm -rf python-build-${CARCH} | true
  cp -r "${_realname}-${pkgver}" "python-build-${CARCH}"
}

build() {
  cd "${srcdir}/python-build-${CARCH}"
  ${MINGW_PREFIX}/bin/python setup.py build
}

check() {
  cd "${srcdir}/python-build-${CARCH}"
  ${MINGW_PREFIX}/bin/python setup.py test || true
}

package() {
  cd "${srcdir}/python-build-${CARCH}"

  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
    ${MINGW_PREFIX}/bin/python setup.py install --prefix=${MINGW_PREFIX} --root="${pkgdir}" -O1

  # fix python command in files
  local _mingw_prefix=$(cygpath -am ${MINGW_PREFIX})
  for _f in "${pkgdir}${MINGW_PREFIX}"/bin/*.py; do
    sed -e "s|${_mingw_prefix}|${MINGW_PREFIX}|g" -i ${_f}
  done

  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/COPYING"
}
